﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapFCHAR(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveFCHAR(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryFCHAR(dwData, 2);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapFCHAR(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertFCHAR(dwLocal);
            }
            UpdateFCHAR(dwLocal);
        }
        public void InsertFCHAR(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "INSERT INTO FCHAR(FCMANDANT, FCCHAR, FCART, FCVAR, FCFARBE, FCGROE, FCAUFM, FCZS, FCEINDAT, FCENTKZ, FCEINLO, FCSPSTA, FCSPGRD, FCME, FCEME, FCEGEB, FCGNRL, FCGNRLPOS, FCLIEFNR, FCLIEFSCH, FCLIEFDAT, FCKZZOLL, FCGEBANZ, FCVPEINH, FCAUFTYP, FCBESTKRS, FCBESTLFD, FCBESTPOS, FCABHS, FCBUDGET, FCRENR, FCREDAT, FCREWERT, FCKZKONSI, FCSTKNR, FCFCODE, FCFILLER, FCAENDZL, FCAENDBEN, FCAENDDAT, FCNEUBEN, FCNEUDAT)"
            + " VALUES (:FCMANDANT, :FCCHAR, '24110040018         ', '  ', '1010      ', 'L      ', '  ', '1A', 20140121, ' ', '01', '  ', '  ', 87, 87, ' ', 0, 0, '00000000', '          ', 0, ' ', 0, '   ', 'V', :FCBESTKRS,:FCBESTLFD, :FCBESTPOS, 0, '        ', '          ', 0, 0, ' ', '            ', '   ', '                                                              ', 1, 'YANGJ   ', 20140121, 'YANGJ   ', 20140121)";
            or1.Parameters.Add("FCMANDANT", OracleType.NVarChar).Value = dwData["FCMANDANT"].ToString();
            or1.Parameters.Add("FCCHAR", OracleType.NVarChar).Value = dwData["FCCHAR"].ToString();
            or1.Parameters.Add("FCBESTKRS", OracleType.NVarChar).Value = dwData["FCBESTKRS"].ToString();
            or1.Parameters.Add("FCBESTLFD", OracleType.NVarChar).Value = dwData["FCBESTLFD"].ToString();
            or1.Parameters.Add("FCBESTPOS", OracleType.NVarChar).Value = dwData["FCBESTPOS"].ToString();
            Connect2Proxy(or1);
        }
        public DataSet QueryFCHAR(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM FCHAR WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM FCHAR "
                        + " WHERE FCMANDANT=:FCMANDANT AND FCAUFTYP=:FCAUFTYP AND FCBESTKRS=:FCBESTKRS AND FCBESTLFD=:FCBESTLFD AND FCBESTPOS=:FCBESTPOS";
                    or1.Parameters.Add("FCMANDANT", OracleType.NVarChar).Value = dwData["FCMANDANT"].ToString();
                    or1.Parameters.Add("FCAUFTYP", OracleType.NVarChar).Value = dwData["FCAUFTYP"].ToString();
                    or1.Parameters.Add("FCBESTKRS", OracleType.NVarChar).Value = dwData["FCBESTKRS"].ToString();
                    or1.Parameters.Add("FCBESTLFD", OracleType.NVarChar).Value = dwData["FCBESTLFD"].ToString();
                    or1.Parameters.Add("FCBESTPOS", OracleType.NVarChar).Value = dwData["FCBESTPOS"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM FCHAR "
           + " WHERE FCMANDANT=:FCMANDANT AND FCCHAR=:FCCHAR";
                    or1.Parameters.Add("FCMANDANT", OracleType.NVarChar).Value = dwData["FCMANDANT"].ToString();
                    or1.Parameters.Add("FCCHAR", OracleType.NVarChar).Value = dwData["FCCHAR"].ToString();
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "FCHAR";
            Return = Result;
            return Return;
        }
        public void UpdateFCHAR(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "UPDATE FCHAR SET "
                        + "FCART=:FCART,"
                        + "FCVAR=:FCVAR,"
                        + "FCFARBE=:FCFARBE,"
                        + "FCGROE=:FCGROE,"
                        + "FCAUFM=:FCAUFM,"
                        + "FCZS=:FCZS,"
                        + "FCEINDAT=:FCEINDAT,"
                        + "FCENTKZ=:FCENTKZ,"
                        + "FCEINLO=:FCEINLO,"
                        + "FCSPSTA=:FCSPSTA,"
                        + "FCSPGRD=:FCSPGRD,"
                        + "FCME=:FCME,"
                        + "FCEME=:FCEME,"
                        + "FCEGEB=:FCEGEB,"
                        + "FCGNRL=:FCGNRL,"
                        + "FCGNRLPOS=:FCGNRLPOS,"
                        + "FCLIEFNR=:FCLIEFNR,"
                        + "FCLIEFSCH=:FCLIEFSCH,"
                        + "FCLIEFDAT=:FCLIEFDAT,"
                        + "FCKZZOLL=:FCKZZOLL,"
                        + "FCGEBANZ=:FCGEBANZ,"
                        + "FCVPEINH=:FCVPEINH,"
                        + "FCAUFTYP=:FCAUFTYP,"
                        + "FCBESTKRS=:FCBESTKRS,"
                        + "FCBESTLFD=:FCBESTLFD,"
                        + "FCBESTPOS=:FCBESTPOS,"
                        + "FCABHS=:FCABHS,"
                        + "FCBUDGET=:FCBUDGET,"
                        + "FCRENR=:FCRENR,"
                        + "FCREDAT=:FCREDAT,"
                        + "FCREWERT=:FCREWERT,"
                        + "FCKZKONSI=:FCKZKONSI,"
                        + "FCSTKNR=:FCSTKNR,"
                        + "FCFCODE=:FCFCODE,"
                        + "FCFILLER=:FCFILLER,"
                        + "FCAENDZL=:FCAENDZL,"
                        + "FCAENDBEN=:FCAENDBEN,"
                        + "FCAENDDAT=:FCAENDDAT,"
                        + "FCNEUBEN=:FCNEUBEN,"
                        + "FCNEUDAT=:FCNEUDAT "
                        + " WHERE FCMANDANT=:FCMANDANT AND FCCHAR=:FCCHAR  ";
                    or1.Parameters.Add("FCMANDANT", OracleType.NVarChar).Value = dwData["FCMANDANT"].ToString();
                    or1.Parameters.Add("FCCHAR", OracleType.NVarChar).Value = dwData["FCCHAR"].ToString();
                    or1.Parameters.Add("FCART", OracleType.NVarChar).Value = dwData["FCART"].ToString();
                    or1.Parameters.Add("FCVAR", OracleType.NVarChar).Value = dwData["FCVAR"].ToString();
                    or1.Parameters.Add("FCFARBE", OracleType.NVarChar).Value = dwData["FCFARBE"].ToString();
                    or1.Parameters.Add("FCGROE", OracleType.NVarChar).Value = dwData["FCGROE"].ToString();
                    or1.Parameters.Add("FCAUFM", OracleType.NVarChar).Value = dwData["FCAUFM"].ToString();
                    or1.Parameters.Add("FCZS", OracleType.NVarChar).Value = dwData["FCZS"].ToString();
                    or1.Parameters.Add("FCEINDAT", OracleType.NVarChar).Value = dwData["FCEINDAT"].ToString();
                    or1.Parameters.Add("FCENTKZ", OracleType.NVarChar).Value = dwData["FCENTKZ"].ToString();
                    or1.Parameters.Add("FCEINLO", OracleType.NVarChar).Value = dwData["FCEINLO"].ToString();
                    or1.Parameters.Add("FCSPSTA", OracleType.NVarChar).Value = dwData["FCSPSTA"].ToString();
                    or1.Parameters.Add("FCSPGRD", OracleType.NVarChar).Value = dwData["FCSPGRD"].ToString();
                    or1.Parameters.Add("FCME", OracleType.NVarChar).Value = dwData["FCME"].ToString();
                    or1.Parameters.Add("FCEME", OracleType.NVarChar).Value = dwData["FCEME"].ToString();
                    or1.Parameters.Add("FCEGEB", OracleType.NVarChar).Value = dwData["FCEGEB"].ToString();
                    or1.Parameters.Add("FCGNRL", OracleType.NVarChar).Value = dwData["FCGNRL"].ToString();
                    or1.Parameters.Add("FCGNRLPOS", OracleType.NVarChar).Value = dwData["FCGNRLPOS"].ToString();
                    or1.Parameters.Add("FCLIEFNR", OracleType.NVarChar).Value = dwData["FCLIEFNR"].ToString();
                    or1.Parameters.Add("FCLIEFSCH", OracleType.NVarChar).Value = dwData["FCLIEFSCH"].ToString();
                    or1.Parameters.Add("FCLIEFDAT", OracleType.NVarChar).Value = dwData["FCLIEFDAT"].ToString();
                    or1.Parameters.Add("FCKZZOLL", OracleType.NVarChar).Value = dwData["FCKZZOLL"].ToString();
                    or1.Parameters.Add("FCGEBANZ", OracleType.NVarChar).Value = dwData["FCGEBANZ"].ToString();
                    or1.Parameters.Add("FCVPEINH", OracleType.NVarChar).Value = dwData["FCVPEINH"].ToString();
                    or1.Parameters.Add("FCAUFTYP", OracleType.NVarChar).Value = dwData["FCAUFTYP"].ToString();
                    or1.Parameters.Add("FCBESTKRS", OracleType.NVarChar).Value = dwData["FCBESTKRS"].ToString();
                    or1.Parameters.Add("FCBESTLFD", OracleType.NVarChar).Value = dwData["FCBESTLFD"].ToString();
                    or1.Parameters.Add("FCBESTPOS", OracleType.NVarChar).Value = dwData["FCBESTPOS"].ToString();
                    or1.Parameters.Add("FCABHS", OracleType.NVarChar).Value = dwData["FCABHS"].ToString();
                    or1.Parameters.Add("FCBUDGET", OracleType.NVarChar).Value = dwData["FCBUDGET"].ToString();
                    or1.Parameters.Add("FCRENR", OracleType.NVarChar).Value = dwData["FCRENR"].ToString();
                    or1.Parameters.Add("FCREDAT", OracleType.NVarChar).Value = dwData["FCREDAT"].ToString();
                    or1.Parameters.Add("FCREWERT", OracleType.NVarChar).Value = dwData["FCREWERT"].ToString();
                    or1.Parameters.Add("FCKZKONSI", OracleType.NVarChar).Value = dwData["FCKZKONSI"].ToString();
                    or1.Parameters.Add("FCSTKNR", OracleType.NVarChar).Value = dwData["FCSTKNR"].ToString();
                    or1.Parameters.Add("FCFCODE", OracleType.NVarChar).Value = dwData["FCFCODE"].ToString();
                    or1.Parameters.Add("FCFILLER", OracleType.NVarChar).Value = dwData["FCFILLER"].ToString();
                    or1.Parameters.Add("FCAENDZL", OracleType.NVarChar).Value = dwData["FCAENDZL"].ToString();
                    or1.Parameters.Add("FCAENDBEN", OracleType.NVarChar).Value = dwData["FCAENDBEN"].ToString();
                    or1.Parameters.Add("FCAENDDAT", OracleType.NVarChar).Value = dwData["FCAENDDAT"].ToString();
                    or1.Parameters.Add("FCNEUBEN", OracleType.NVarChar).Value = dwData["FCNEUBEN"].ToString();
                    or1.Parameters.Add("FCNEUDAT", OracleType.NVarChar).Value = dwData["FCNEUDAT"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
    }
}
